package com.example.baseutils

object TimeFormat {
    private val sb = StringBuffer()
    private val sb2 = StringBuffer()
    private val sbReal = StringBuffer()
    //格式化时间
    fun formatTimeReal(ms: Long): String {
        sbReal.setLength(0)
        val ss = 1000
        val mi = ss * 60
        val hh = mi * 60
        val dd = hh * 24
        val day = ms / dd
        val hour = (ms - day * dd) / hh
        val minute = (ms - day * dd - hour * hh) / mi
        val second = (ms - day * dd - hour * hh - minute * mi) / ss
        val milliSecond = (ms - day * dd - hour * hh - minute * mi - second * ss) / 10
        if (day > 0) {
            sbReal.append(day.toString() + "天")
        }
        if (hour > 0) {
            sbReal.append(hour.toString() + "小时")
        }
        if (minute in 1..9) {
            sbReal.append("0$minute:")
        } else if (minute >= 10) {
            sbReal.append("$minute:")
        } else {
            sbReal.append("00:")
        }
        if (second in 1..9) {
            sbReal.append("0$second.")
        } else if (second >= 10) {
            sbReal.append("$second.")
        } else {
            sbReal.append("00.")
        }
        if (milliSecond in 1..9) {
            sbReal.append("0$milliSecond")
        } else if (milliSecond >= 10) {
            sbReal.append("$milliSecond")
        } else {
            sbReal.append("00")
        }
        return sbReal.toString()
    }
    //格式化时间
     fun formatTime(ms: Long): String {
        sb.setLength(0)
        val ss = 1000
        val mi = ss * 60
        val hh = mi * 60
        val dd = hh * 24
        val day = ms / dd
        val hour = (ms - day * dd) / hh
        val minute = (ms - day * dd - hour * hh) / mi
        val second = (ms - day * dd - hour * hh - minute * mi) / ss
        val milliSecond = (ms - day * dd - hour * hh - minute * mi - second * ss) / 10
        if (day > 0) {
            sb.append(day.toString() + "天")
        }
        if (hour > 0) {
            sb.append(hour.toString() + "小时")
        }
        if (minute in 1..9) {
            sb.append("0$minute:")
        } else if (minute >= 10) {
            sb.append("$minute:")
        } else {
            sb.append("00:")
        }
        if (second in 1..9) {
            sb.append("0$second.")
        } else if (second >= 10) {
            sb.append("$second.")
        } else {
            sb.append("00.")
        }
        if (milliSecond in 1..9) {
            sb.append("0$milliSecond")
        } else if (milliSecond >= 10) {
            sb.append("$milliSecond")
        } else {
            sb.append("00")
        }
        return sb.toString()
    }
//格式化时间
     fun formatTime2(ms: Long): String {
        sb2.setLength(0)
        val ss = 1000
        val mi = ss * 60
        val hh = mi * 60
        val dd = hh * 24
        val day = ms / dd
        val hour = (ms - day * dd) / hh
        val minute = (ms - day * dd - hour * hh) / mi
        val second = (ms - day * dd - hour * hh - minute * mi) / ss
        val milliSecond = (ms - day * dd - hour * hh - minute * mi - second * ss) / 10
        if (day > 0) {
            sb2.append(day.toString() + "天")
        }
        if (hour > 0) {
            sb2.append(hour.toString() + "小时")
        }
        if (minute in 1..9) {
            sb2.append("0$minute:")
        } else if (minute >= 10) {
            sb2.append("$minute:")
        } else {
            sb2.append("00:")
        }
        if (second in 1..9) {
            sb2.append("0$second.")
        } else if (second >= 10) {
            sb2.append("$second.")
        } else {
            sb2.append("00.")
        }
        if (milliSecond in 1..9) {
            sb2.append("0$milliSecond")
        } else if (milliSecond >= 10) {
            sb2.append("$milliSecond")
        } else {
            sb2.append("00")
        }
        return sb2.toString()
    }

}